package com.flyone.herbal.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flyone.herbal.constant.CommonConstant;
import com.flyone.herbal.model.dto.medicine.MedicineQueryRequest;
import com.flyone.herbal.model.entity.ChineseMedicinalFormulae;
import com.flyone.herbal.service.ChineseMedicinalFormulaeService;
import com.flyone.herbal.mapper.ChineseMedicinalFormulaeMapper;
import com.flyone.herbal.utils.SqlUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luoyifei
 * @description 针对表【中药方剂】的数据库操作Service实现
 * @createDate 2024-04-20 11:28:56
 */
@Service
public class ChineseMedicinalFormulaeServiceImpl extends ServiceImpl<ChineseMedicinalFormulaeMapper, ChineseMedicinalFormulae>
        implements ChineseMedicinalFormulaeService {

    @Override
    public QueryWrapper<ChineseMedicinalFormulae> getQueryWrapper(MedicineQueryRequest medicineQueryRequest) {
        QueryWrapper<ChineseMedicinalFormulae> queryWrapper = new QueryWrapper<>();
        if (medicineQueryRequest == null) {
            return queryWrapper;
        }
        String keyword = medicineQueryRequest.getKeyword();
        String sortField = medicineQueryRequest.getSortField();
        String sortOrder = medicineQueryRequest.getSortOrder();
        // 拼接查询条件
        if (StringUtils.isNotBlank(keyword)) {
            queryWrapper.like("名称", keyword).or()
                    .like("拼音", keyword)
                    .or()
                    .like("分类", keyword)
                    .or()
                    .like("组成", keyword)
                    .or()
                    .like("用法", keyword)
                    .or()
                    .like("功用", keyword)
                    .or()
                    .like("主治", keyword)
                    .or()
                    .like("病机", keyword)
                    .or()
                    .like("运用", keyword)
                    .or()
                    .like("方歌", keyword)
                    .or()
                    .like("出处", keyword);
        }
        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
                sortField);
        return queryWrapper;
    }
}




